package org.edu.modules.logistics.base.service.impl;

import cn.hutool.core.util.StrUtil;
import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.logistics.base.dto.VeHqBgwpflDto;
import org.edu.modules.logistics.base.mapper.VeHqCangkuMapper;
import org.edu.modules.logistics.base.entity.VeHqCangku;
import org.edu.modules.logistics.base.dto.VeHqCangkuDto;
import org.edu.modules.logistics.base.service.VeHqCangkuService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * 实现类
 */
@Service
public class VeHqCangkuServiceImpl extends BaseServiceImpl<VeHqCangku, VeHqCangkuMapper> implements VeHqCangkuService {

    public IPage<VeHqCangkuDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeHqCangkuDto findDtoById(String id) {
        VeHqCangku entity = super.findById(id);
        VeHqCangkuDto dto = ConvertUtils.convertToDto(entity, VeHqCangkuDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeHqCangkuDto dto,Boolean isAdd){
        if(isAdd){
            super.insert(dto);
        }else{
            super.update(dto);
        }
    }


    @Override
    public void importExcel(List<Map<String, Object>> mapList) throws Exception {
        for (int i = 1; i < mapList.size(); i++) {
            Map map= mapList.get(i);
            VeHqCangkuDto dto = new VeHqCangkuDto();
            dto.setStatus(1);
            dto.setName((String)map.get(0));
            dto.setAddress((String)map.get(1));
            dto.setPhone((String)map.get(4));
            dto.setRemark((String) map.get(5));


            String gonghao = (String)map.get(2);

            this.insertOrUpdate(dto,true);
        }
    }

}
